﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SmartMeterParamSetting.UI
{
    /// <summary>
    /// UI_DataView.xaml 的交互逻辑
    /// </summary>
    public partial class UI_DataView : Window
    {
        public UI_DataView()
        {
            InitializeComponent();
        }

        public UI_DataView(SmartMeterParamFrame.Model.MeterCollection mCollection,SmartMeterParamFrame.Model.FACollection faCollection)
            : this()
        {

            SmartMeterParamFrame.EnumResult result = SmartMeterParamFrame.EnumResult.未操作;

            for (int i = 0; i < mCollection.Count; i++)
            {
                SmartMeterParamFrame.Model.MeterInfo meterItem = mCollection[i];

                TreeViewItem item = new TreeViewItem();

                DockPanel dp = new DockPanel();

                dp.LastChildFill = true;

                TextBlock Txt_Name = new TextBlock();

                Txt_Name.Text = string.Format("第【{0:d2}】表位:{1}    操作结果：", meterItem.MeterBwh, meterItem.MeterAddress);

                TextBlock Txt_Result = new TextBlock();

                result = meterItem.OperationResult;

                Txt_Result.Foreground = result == SmartMeterParamFrame.EnumResult.失败 ? Brushes.Red : Brushes.Black;

                Txt_Result.Text = result.ToString();

                dp.Children.Add(Txt_Name);

                dp.Children.Add(Txt_Result);
                item.Header = dp;

                for (int j = 0; j < faCollection.Count; j++)
                {
                    SmartMeterParamFrame.Model.FAinfo faItem = faCollection[j];

                    TreeViewItem childItem = new TreeViewItem();

                    DockPanel childDp = new DockPanel();

                    childDp.LastChildFill = true;

                    TextBlock[] Txt_Caption = new TextBlock[5];

                    Txt_Caption[0] = new TextBlock();

                    Txt_Caption[0].Width = 160;

                    Txt_Caption[0].Text = string.Format("项目：{0}", faItem.PrjName);

                    Txt_Caption[1] = new TextBlock();

                    Txt_Caption[1].Text = "设置结果：";

                    Txt_Caption[2] = new TextBlock();

                    Txt_Caption[2].Width = 100;

                    result=meterItem.getPrjResult(faItem.PrjOrderID, false);

                    Txt_Caption[2].Foreground=result != SmartMeterParamFrame.EnumResult.失败?  Brushes.Black:Brushes.Red;

                    Txt_Caption[2].Text = result.ToString();

                    Txt_Caption[3] = new TextBlock();

                    Txt_Caption[3].Text = "复核结果：";

                    Txt_Caption[4] = new TextBlock();

                    result=meterItem.getPrjResult(faItem.PrjOrderID, true);

                    Txt_Caption[4].Foreground = result != SmartMeterParamFrame.EnumResult.失败 ? Brushes.Black : Brushes.Red;

                    Txt_Caption[4].Text = result.ToString();

                    foreach(TextBlock t in Txt_Caption)
                    {
                        t.Margin=new Thickness(2);
                        t.TextTrimming = TextTrimming.CharacterEllipsis;
                        childDp.Children.Add(t);
                    }

                    item.Items.Add(childDp);
                }
                Tree_Data.Items.Add(item);
            }

        }


    }
}
